﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Raise3000.Code;
using Raise3000.Code.HandHistoryLoader;
using Raise3000.Code.Helpers;

namespace Raise3000
{
    public partial class MainApplicationForm : Form
    {
        // members
        PlayerTemplateManager PlayerTemplateManger_ = null;

        public MainApplicationForm()
        {
            InitializeComponent();

            //Initializing logger
            LoggerHelper logger = LoggerHelper.GetLoggerHelper();
            logger.InitializeGeneralLog(generalLogTextBox);
            logger.InitializeSQLLog(sqlTextBox);

            PlayerTemplateManger_ = new PlayerTemplateManager();
        }

        private void playerTemplatesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //CreatePlayerTemplates rt = new CreatePlayerTemplates();
            //rt.ShowDialog();
        }

        private void createNewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Creating new player template         
            PlayerTemplateDialog ptDialog = new PlayerTemplateDialog();
            
            PlayerTemplate pt = new PlayerTemplate();
            ptDialog.PTemplate = pt;
            ptDialog.Mode = OperatingMode.eCREATENEW;

            DialogResult result = ptDialog.ShowDialog();
            // we have had created a valid new one.
            if (result == DialogResult.OK)
            {                
                PlayerTemplateManger_.Add(ptDialog.PTemplate);
            }
        }

        private void editExistingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List<string> playerTemplates = PlayerTemplateManger_.GetPlayerTemplatesNames();
            PlayerTemplateSelector pts = new PlayerTemplateSelector(playerTemplates);

            DialogResult result = pts.ShowDialog();
            if (result == DialogResult.OK)
            {
                string selectedPlayerTemplate = pts.GetSelectedPlayerTemplateName();

                PlayerTemplate pt = PlayerTemplateManger_.FindPlayerTemplateByName(selectedPlayerTemplate);

                PlayerTemplateDialog ptDialog = new PlayerTemplateDialog();
                ptDialog.PTemplate = pt;
                ptDialog.Mode = OperatingMode.eEDITEXISTING;

                if (ptDialog.ShowDialog() == DialogResult.OK)
                {
                    // what we have done?
                }
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {            
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                List<string> handHistory = new List<string>();
                handHistory.Add(openFileDialog1.FileName);

                HandHistoryManager handHistoryManager = new HandHistoryManager("AbsolutePoker", "0.05/0.10", 4, handHistory);

                List<PlayerTemplate> playerTemplates = handHistoryManager.CreatePlayerTemplatesFromHistory();
            }
        }
    }
}
